<?php

namespace App\Http\Controllers\Logic;

use App\Http\Controllers\Controller;
use App\Model\OAStaff;
use App\Model\OAZhidu;
use Illuminate\Http\Request;

class ZhiDuLogic extends Controller
{
    public function getList($input)
    {
        $query =  OAZhidu::query();
        if(isset($input['header']) && !empty($input['header'])) $query->where('header','like','%'.$input['header'].'%');
        if(isset($input['username']) && !empty($input['username'])) $query->where('username',$input['username']);
        return $query->orderBy('create_at','DESC')->paginate($input['page_size'],['*']);
    }

    //添加制度
    public function addZhidu(&$input)
    {
        $input['state'] = 1;
        $input['username'] = OAStaff::query()->where('id',$input['uid'])->value('username');
        $input['create_at'] = date('Y-m-d H:i:s');
        unset($input['uid'],$input['roleid'],$input['deptid']);
        if(isset($input['id']) && !empty($input['id'])){
            return OAZhidu::query()->where('id',$input['id'])->update($input);
        }else{
            return OAZhidu::query()->insertGetId($input);
        }

    }
}
